// Lorin产品模型
class LorinProductModel {
  // 产品型号字符串长度
  final int productModelStrLen = 12;

  // 主系列
  int mainSeries = 0;

  // 子系列
  int subSeries = 0;

  // 产品型号
  int type = 0;

  // 批次
  int batch = 0;

  // 接口特征
  int interfaceFeature = 0;

  // 保留
  int reserved = 0;

  LorinProductModel.fromHexString(String productModel) {
    if (productModel.length != productModelStrLen) {
      throw Exception(
          'Invalid product model, lenght = (productModel.length), length must be $productModelStrLen');
    }
    mainSeries = int.parse(productModel.substring(0, 2), radix: 16);
    subSeries = int.parse(productModel.substring(2, 4), radix: 16);
    type = int.parse(productModel.substring(4, 6), radix: 16);
    batch = int.parse(productModel.substring(6, 8), radix: 16);
    interfaceFeature = int.parse(productModel.substring(8, 10), radix: 16);
    reserved = int.parse(productModel.substring(10, 12), radix: 16);
  }

  String get toHexString {
    return '${mainSeries.toRadixString(16).padLeft(2, '0')}'
        '${subSeries.toRadixString(16).padLeft(2, '0')}'
        '${type.toRadixString(16).padLeft(2, '0')}'
        '${batch.toRadixString(16).padLeft(2, '0')}'
        '${interfaceFeature.toRadixString(16).padLeft(2, '0')}'
        '${reserved.toRadixString(16).padLeft(2, '0')}';
  }
}
